﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using td.Core;
using td.Core.DiscoverAddins;
using System.Threading;
using CG.Security.Principal;

namespace td.Core
{
    public class SecurityViewTest : td.Core.AbstractViewContent
    {
       // td.Core.Security.MainForm view = new Core.Security.MainForm();
        td.Core.Security.UserManagerForm view = new Security.UserManagerForm();
        public override DevExpress.XtraEditors.XtraUserControl ViewContentControl
        {
            get { return this.view; }
        }
        public override string Title
        {
            get
            {
                return "用户管理";
            }
            set
            {
                base.Title = value;
            }
        }
    }
    public class SecurityUserManagerCommand:td.Core.AbstractToolButtonCommand
    {
        public override void Run()
        {
            var p = WorkBenchSingleTon.WorkBench.GetTabPage("用户管理");
            if (p == null)
            {
                WorkBenchSingleTon.WorkBench.AddView(new SecurityViewTest());
            }
        }
        public override bool IsEnabled
        {
            get
            {
                var p = WorkBenchSingleTon.WorkBench.GetTabPage("用户管理");
                CustomPrincipal cp = (CustomPrincipal)Thread.CurrentPrincipal; ;
                CustomIdentity ci = (CustomIdentity)cp.Identity;

                return p == null && cp.IsInRole("Admin");
                
                
            }
            set
            {
                base.IsEnabled = value;
            }
        }
    }
}
